// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//
#pragma once

#include <boost/random/uniform_int_distribution.hpp>
#include <pollux/testing/expression/arg_types_generator.h>
#include <pollux/functions/sparksql/decimal_util.h>

namespace kumo::pollux::functions::sparksql::fuzzer {

class MakeTimestampArgTypesGenerator : public pollux::fuzzer::ArgTypesGenerator {
 public:
  std::vector<TypePtr> generateArgs(
      const exec::FunctionSignature& signature,
      const TypePtr& returnType,
      FuzzerGenerator& rng) override {
    const auto s = 6;
    const auto p = rand32(s, ShortDecimalType::kMaxPrecision, rng);
    std::vector<TypePtr> types = {
        INTEGER(), INTEGER(), INTEGER(), INTEGER(), INTEGER(), DECIMAL(p, s)};

    if (signature.argumentTypes().size() == 6) {
      return types;
    }
    types.push_back(VARCHAR());
    return types;
  }

 private:
  static uint32_t rand32(uint32_t min, uint32_t max, FuzzerGenerator& rng) {
    return boost::random::uniform_int_distribution<uint32_t>(min, max)(rng);
  }
};

} // namespace kumo::pollux::functions::sparksql::fuzzer
